﻿using System;
using System.Data;
using ChapterX.BusinessFacade;
using ChapterX.Common;
using ChapterX.Data.CoursesDSTableAdapters;

namespace ChapterX.Modules
{
    public partial class CourseListModule : ChapterX.Model.DataListModuleBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindCourseList();
            }
        }

        protected void BindCourseList()
        {
            try
            {
                TeacherCourseViewTableAdapter adpater = new TeacherCourseViewTableAdapter();
                DataTable courseList = null;

                if (CurrentUserInfo.IsTeacher)
                {
                    courseList = adpater.GetCourseListByTeacherId(CurrentUserInfo.Username);
                }
                else
                {
                    courseList = adpater.GetData();
                }

                CourseList.DataSource = courseList;
                CourseList.DataBind();
            }
            catch (Exception ex)
            {
                SetErrorMessage("数据绑定失败。");
                Logger.Log(ex);
            }
        }
    }
}